feat: Add compare_directories tool for directory comparison#3890
feat: Add compare_directories tool for directory comparison#3890nagual2 wants to merge 11 commits intomodelcontextprotocol:mainfrom
Conversation
… usage, add types
…archFilesWithValidation calls
olaservo
left a comment
There was a problem hiding this comment.
Thanks for the contribution. A couple of implementation issues and a scope question:
Implementation issues:
- The
compareContentparameter is accepted in the schema and function signature but never used — comparison always uses size/mtime regardless of the flag. Either implement content comparison or remove the parameter. - Files with identical content but different timestamps will be reported as "different," and files with different content but the same size/mtime will be reported as "identical." This should at least be documented clearly, or addressed with actual content hashing when
compareContentis true.
Scope question:
Per our CONTRIBUTING.md, we're selective about new features that aren't core to a server's purpose. Directory comparison feels like it could be composed by an LLM using existing tools (directory_tree, read_file), or handled by a dedicated server. Would you consider publishing this as a standalone MCP server on the Registry instead?
This review was assisted by Claude Code.
- Add compareFileContents helper for byte-by-byte comparison - compareContent=true now reads and compares actual file contents - Files with same content (but different mtime) go to identical - Fix: compareContent parameter is now actually used - When sizes differ, skip content comparison for efficiency
- Test same-size different-content detection with compareContent=true - Test same-content different-mtime detection (should be identical) - Test binary file content comparison - Test compareContent=false behavior (mtime-based)
|
@olaservo Thanks for the detailed review! I've addressed the implementation issues: Fixed:
|
- save and restore global allowedDirectories state - fixes tests that expect validatePath to work with test directories
The test was writing to marker.txt expecting diff-mtime.txt mtime to change. Now it directly re-writes diff-mtime.txt to update its mtime.
Summary
Adds
compare_directoriestool to filesystem MCP server for comparing two directory structures.New Tool:
compare_directoriesCompares two directories and returns:
Changes
src/filesystem/lib.ts- AddedcompareDirectories()functionsrc/filesystem/index.ts- Registered toolsrc/filesystem/__tests__/lib.test.ts- Added 6 testsTests
✅ Files unique to each directory
✅ Content difference detection
✅ Identical file identification
✅ Empty directory handling
✅ Nested structures
All tests pass with
npm test.